package com.jf.controller;

import com.jf.entity.Student;
import com.jf.service.IStudentService;
import com.jf.util.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 类名：
 * 作者：WF
 * 功能：
 */
@RestController
@RequestMapping("/student")
public class StudentController {
	@Autowired
	private IStudentService studentService;
	/**
	 * 1. 查询所有学生
	 * http://localhost:9000/student/list
	 */
	@RequestMapping("/list")
	public List<Student> list(){
		List<Student> students = studentService.findStudents();
		return students;
	}

	/**
	 * 2. 分页查询学生
	 */
	@GetMapping("/findByPage/{page}/{pageSize}")
	// 地址类似于： http://localhost:9000/student/findByPage/1/5
	public PageResult<Student> findByPage(@PathVariable("page") int page,
	                                      @PathVariable("pageSize") int pageSize){
		PageResult<Student> studentPage = studentService.findByPage(page, pageSize);
		return studentPage;
	}
}
